<script lang="ts">
export default {
  name: "My",
  beforeCreate() {
    if(!localStorage.getItem('username')){
      this.$router.push({
        path:'/login',
        query:{
          returnUrl:'/my'
        }
      })
    }
  },
  methods:{
    outLogin(){
      localStorage.clear();
      this.$router.push({
        path:'/login',
        query:{
          returnUrl:'/my'
        }
      })
    }
  },
  computed:{
    username(){
      return localStorage.getItem('username')
    }
  }
}
</script>

<template>
  <div>
    <h3>欢迎{{username}}进入</h3>
    <button @click="outLogin">退出登录</button>
  </div>

</template>

<style scoped lang="less">

</style>
